home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / rootkits / rootkit / unix.c < prev    next >
Text File  |  1994-03-01  |  3KB  |  110 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. static    char sccsid[] = "@(#)unix.c 1.1 91/11/13 SMI"; /* from UCB 5.3 5/8/86 */
  9. #endif
  10.  
  11. /*
  12.  * Display protocol blocks in the unix domain.
  13.  */
  14. #include <sys/param.h>
  15. #include <sys/protosw.h>
  16. #include <sys/socket.h>
  17. #include <sys/socketvar.h>
  18. #include <sys/mbuf.h>
  19. #include <sys/un.h>
  20. #include <sys/unpcb.h>
  21. #define    KERNEL
  22. #include <sys/file.h>
  23.  
  24. int    Aflag;
  25. int    kread();
  26.  
  27. unixpr(nfileaddr, fileaddr, unixsw)
  28.     off_t nfileaddr, fileaddr;
  29.     struct protosw *unixsw;
  30. {
  31.     register struct file *fp;
  32.     struct file *filep;
  33.     struct socket sock, *so = &sock;
  34.  
  35.     if (nfileaddr == 0 || fileaddr == 0) {
  36.         printf("nfile or file not in namelist.\n");
  37.         return;
  38.     }
  39.     if (kread(nfileaddr, &nfile, sizeof (nfile)) != sizeof (nfile)) {
  40.         printf("nfile: bad read.\n");
  41.         return;
  42.     }
  43.     if (kread(fileaddr, &filep, sizeof (filep)) != sizeof (filep)) {
  44.         printf("File table address, bad read.\n");
  45.         return;
  46.     }
  47.     file = (struct file *)calloc(nfile, sizeof (struct file));
  48.     if (file == (struct file *)0) {
  49.         printf("Out of memory (file table).\n");
  50.         return;
  51.     }
  52.     if (kread((off_t)filep, file, nfile * sizeof (struct file)) !=
  53.         nfile * sizeof (struct file)) {
  54.         printf("File table read error.\n");
  55.         return;
  56.     }
  57.     fileNFILE = file + nfile;
  58.     for (fp = file; fp < fileNFILE; fp++) {
  59.         if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
  60.             continue;
  61.         if (kread(fp->f_data, so, sizeof (*so)) != sizeof (*so))
  62.             continue;
  63.         /* kludge */
  64.         if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
  65.             if (so->so_pcb)
  66.                 unixdomainpr(so, fp->f_data);
  67.     }
  68.     free((char *)file);
  69. }
  70.  
  71. static    char *socktype[] =
  72.     { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
  73.  
  74. unixdomainpr(so, soaddr)
  75.     register struct socket *so;
  76.     caddr_t soaddr;
  77. {
  78.     struct unpcb unpcb, *unp = &unpcb;
  79.     struct mbuf mbuf, *m;
  80.     struct sockaddr_un *sa;
  81.     static int first = 1;
  82.  
  83.     if (kread(so->so_pcb, unp, sizeof (*unp)) != sizeof (*unp))
  84.         return;
  85.     if (unp->unp_addr) {
  86.         m = &mbuf;
  87.         if (kread(unp->unp_addr, m, sizeof (*m)) != sizeof (*m))
  88.             m = (struct mbuf *)0;
  89.         sa = mtod(m, struct sockaddr_un *);
  90.     } else
  91.         m = (struct mbuf *)0;
  92.     if (first) {
  93.         printf("Active UNIX domain sockets\n");
  94.         printf(
  95. "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
  96.             "Address", "Type", "Recv-Q", "Send-Q",
  97.             "Vnode", "Conn", "Refs", "Nextref");
  98.         first = 0;
  99.     }
  100.     printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x",
  101.         soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc,
  102.         unp->unp_vnode, unp->unp_conn,
  103.         unp->unp_refs, unp->unp_nextref);
  104.     if (m)
  105.         printf(" %.*s", m->m_len - sizeof(sa->sun_family),
  106.             sa->sun_path);
  107.     putchar('\n');
  108. }
  109.  
  110.